# GoldTree Makefile for Wails Desktop App

.PHONY: help dev build clean install deps test

# 默认目标
all: build

# 显示帮助信息
help:
	@echo "GoldTree 桌面应用构建工具"
	@echo ""
	@echo "可用命令:"
	@echo "  make dev     - 启动开发模式（热重载）"
	@echo "  make build   - 构建生产版本"
	@echo "  make clean   - 清理构建文件"
	@echo "  make install - 安装依赖"
	@echo "  make deps    - 更新依赖"
	@echo "  make test    - 运行测试"
	@echo "  make web     - 启动Web版本"
	@echo ""

# 开发模式
dev:
	@echo "启动开发模式..."
	wails dev

# 构建应用
build: deps
	@echo "构建 GoldTree 桌面应用..."
	wails build -ldflags "-s -w"

# 构建所有平台版本
build-all: deps
	@echo "构建所有平台版本..."
	wails build -platform windows/amd64 -ldflags "-s -w"
	wails build -platform darwin/universal -ldflags "-s -w"
	wails build -platform linux/amd64 -ldflags "-s -w"

# 清理构建文件
clean:
	@echo "清理构建文件..."
	rm -rf ./build/
	rm -f ./goldtree
	rm -f ./goldtree.exe

# 安装 Wails
install:
	@echo "安装 Wails..."
	go install github.com/wailsapp/wails/v2/cmd/wails@latest

# 更新依赖
deps:
	@echo "更新依赖..."
	go mod tidy
	go mod download

# 运行测试
test:
	@echo "运行测试..."
	go test ./...

# 启动Web版本（传统模式）
web:
	@echo "启动Web版本..."
	go run main.go

# 检查环境
check:
	@echo "检查构建环境..."
	@echo "Go 版本:"
	@go version
	@echo "Wails 版本:"
	@wails version || echo "Wails 未安装"
	@echo "Node.js 版本:"
	@node --version || echo "Node.js 未安装"

# 生成应用图标（需要安装 imagemagick）
icon:
	@echo "生成应用图标..."
	@if [ -f "assets/logo.png" ]; then \
		mkdir -p build; \
		convert assets/logo.png -resize 256x256 build/appicon.png; \
		convert assets/logo.png -resize 16x16,32x32,48x48,256x256 build/appicon.ico; \
		echo "图标生成完成"; \
	else \
		echo "请先准备 assets/logo.png 文件"; \
	fi

# 打包发布
package: build
	@echo "打包发布版本..."
	@mkdir -p dist
	@if [ -f "build/bin/goldtree.exe" ]; then \
		zip -r dist/goldtree-windows-amd64.zip build/bin/goldtree.exe; \
	fi
	@if [ -f "build/bin/GoldTree.app" ]; then \
		zip -r dist/goldtree-darwin-universal.zip build/bin/GoldTree.app; \
	fi
	@if [ -f "build/bin/goldtree" ]; then \
		tar -czf dist/goldtree-linux-amd64.tar.gz -C build/bin goldtree; \
	fi
	@echo "打包完成，文件位于 dist/ 目录"